package com.qf.service.impl;

import com.qf.dao.UserDao;
import com.qf.dao.impl.UserDaoImpl;
import com.qf.pojo.User;
import com.qf.service.UserService;

public class UserServiceImpl implements UserService {
    UserDao userDao = new UserDaoImpl();
    @Override
    public boolean checkUserName(String username) {
        //查询数据库是否存在此用户名
        //发起查询：根据用户名查询用户的个数
           long count= userDao.selectCountByUserName(username);

        return count>0;
    }

    @Override
    public boolean register(String username, String password, String email, String gender) {
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        user.setGender(gender);
        user.setEmail(email);
        //设置用户的状态为 激活
        user.setFlag(1);
        // 激活码
//        user.setCode();
        int count= userDao.insert(user);

        return count==1;
    }

    @Override
    public User login(String username, String password) {
        User user=userDao.selectByUserNameAndPassword(username,password);

        return user;
    }
}
